/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package framework11;

import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import javax.swing.JOptionPane;

/**
 *
 * @author Montu
 */
    
public class LeerArchivojava {
    Atributos[] Atributo = new Atributos[100];
//    ArrayList Atributo = new ArrayList();
    int CantAtributos=0;
    
    File Fichero;
    String nombre = null;
    ObjectInputStream entrada;
    FileInputStream FileClase;
    BufferedInputStream BufFile;
    DataInputStream DataClase;
    String pack;
    public LeerArchivojava(String Ruta){
        Fichero = new File(Ruta);
        entrada = null;
        FileClase = null;
        BufFile = null;
        DataClase = null;
        leer();
    }
    
    private void leer(){
        try {
            FileClase = new FileInputStream(Fichero);
            BufFile = new BufferedInputStream(FileClase);
            DataClase = new DataInputStream(BufFile);
            String linea;
            int contpack1 = 0;
            String tipo;
            
            while (DataClase.available() != 0) {
                linea = DataClase.readLine().trim();
                if (!linea.equals("") && !linea.equals("\n") && linea.length()>=7){
                    if (linea.substring(0,7).equals("package"))
                    {
                        contpack1=7;
                        do{
                           contpack1++;
                        }while(linea.charAt(contpack1)!=';');
                        System.out.println(linea.substring(7, contpack1) + "package");
                        pack = linea.substring(7, contpack1);
                    }
                    if (linea.substring(0,7).equals("private")){
                        int cont2=7;
                        do{
                           cont2++;
                        }while(linea.charAt(cont2)!=' ');
                        int ini=cont2;
                        do{
                            cont2++;
                        }while(linea.charAt(cont2)!=';');
                        System.out.println(linea.substring(ini+1, cont2));
                        
                        System.out.println(linea.substring(8, ini));
                        nombre = linea.substring(ini+1,cont2);
                        
                        tipo = linea.substring(8, ini);
                        Atributo[CantAtributos] = new Atributos(nombre, tipo);
//                        Atributos atri = new Atributos(nombre, tipo);
//                        Atributo.add(atri);
                        CantAtributos++;
                    }  
                }
                             
            }
            FileClase.close();
            BufFile.close();
            DataClase.close();
            
            } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    
    public String getpack()
    {
        return pack;
    }
    
    public int VerCantidadAtributos(){
        return CantAtributos;
    }
    
    public Atributos[] VerAtributos(){
       return Atributo;
    }
}
